package com.pattern.singleton.type3;

/**
 * @author 冯志立
 * @create 2019-10-17 11:46
 * 双重检查
 */
public class SingletonTest {
}

//双重检查 推荐使用  保证线程安全，也避免反复进行方法同步
class Singleton{
    private static volatile Singleton singleton;

    private Singleton(){};

    public static Singleton getInstance(){
        if (singleton == null){
            synchronized (Singleton.class){
                if (singleton == null){
                    singleton = new Singleton();
                }
            }
        }
        return singleton;
    }
}